/* Copyright 2001,2002,2003 NAH6
 * All Rights Reserved
 *
 * Parts Copyright DoD, Parts Copyright Starium
 *
 */
/***************************************************************************

 ROUTINE
               variance

 FUNCTION
                
               calculates variance of the input array

 SYNOPSIS
               subroutine variance(arr,no,var,avg)

   formal 

                       data    I/O
       name            type    type    function
       -------------------------------------------------------------------
       arr		real	i	input data array
       no		int	i	number of elements in array
       var		real	o	variance
       avg		real	o	average


**************************************************************************/
#include "variance.h"

void variance(
float 	*arr,
int 	no,
float 	*var,
float 	*avg)
{ int i;
  float sum = 0.0, sum2 = 0.0, tavg;

  for (i=0; i < no; i++)
    sum += arr[i];
  tavg = sum / (float) no;

  for (i = 0; i < no; i++)
    sum2 += (tavg - arr[i]) * (tavg - arr[i]);

  *avg = tavg;
  *var = sum2 / (float) (no-1);
}
